package com.gpnu.crm.service.impl;


import com.gpnu.crm.domain.Customer;
import com.gpnu.crm.domain.Employee;
import com.gpnu.crm.domain.FormalCustomer;
import com.gpnu.crm.mapper.CustomerMapper;
import com.gpnu.crm.mapper.FormalCustomerMapper;
import com.gpnu.crm.query.QueryObject;
import com.gpnu.crm.service.IFormalCustomerService;
import com.gpnu.crm.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FormalCustomerServiceImpl implements IFormalCustomerService {
    @Autowired
    private FormalCustomerMapper formalCustomerMapper;
    @Autowired
    private CustomerMapper customerMapper;

    public PageInfo<FormalCustomer> query(QueryObject qo) {
        PageHelper.startPage((int)qo.getCurrentPage(), (int)qo.getPageSize(), (String)qo.getOrderby());
        List list = this.formalCustomerMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void save(FormalCustomer entity) {
        entity.setVdate(new Date());
        entity.setSeller(UserContext.getCurrentUser());
        this.formalCustomerMapper.insert(entity);
        this.customerMapper.updateCustomerInfo(entity.getCustomer().getId(), null, Customer.STATUS_FORMAL);
    }
}